<template>
  <!-- 新增类型dialog -->
  <Edialog
    title="调整分组"
    :outershow="show"
    saveClick
    @close="closeFn"
    @saveFn="saveFn"
  >
    <div style="padding: 0 20px">
      <el-form ref="form" :model="form" label-width="80px" :rules="leftRules">
        <el-form-item prop="groupName" label="原分组">
          <el-input v-model="form.groupName" disabled></el-input>
        </el-form-item>
        <el-form-item label="新分组">
          <Eselect
            style="width: 100%"
            isClearable
            :options="sendArr"
            :value="form.groupId"
            @EselectChange="form.groupId = $event"
            size="medium"
          ></Eselect>
        </el-form-item>
      </el-form>
    </div>
  </Edialog>
</template>

<script>
import Edialog from '@/components/Edialog'
import Eselect from '@/components/Eselect'
import { getContactsGroupData } from '@/utils/publicReq'
import { postDoAdjustGroup } from '@/api/smsManage/groupContacts'
import { fd } from '@/utils/index'
export default {
  components: {
    Edialog,
    Eselect
  },
  data () {
    return {
      show: false,
      // 分组数据
      sendArr: [],
      form: {
        groupName: '',
        groupId: '',
        ids: ''
      },
      leftRules: {
        groupName: [{ required: true, message: '请输入', trigger: 'blur' }]
      }
    }
  },
  methods: {
    async open (scope) {
      this.sendArr = await getContactsGroupData()
      this.form.groupName = scope.groupName
        ? scope.groupName
        : '未分组（默认分组）'
      this.form.ids = scope.id
      this.show = true
    },
    // 保存事件
    saveFn () {
      this.$refs.form.validate(async valid => {
        if (valid) {
          let obj = JSON.parse(JSON.stringify(this.form))
          obj.ids = JSON.stringify(obj.ids)
          let res = await postDoAdjustGroup(fd(this.form))
          if (res.data && res.data.bcode == 0) {
            this.$parent.getTabelDataFn()
            this.closeFn()
            this.$message.success(res.data.bmsg)
          }
        }
      })
    },
    closeFn () {
      this.form.groupName = ''
      this.form.groupId = ''
      this.form.ids = ''
      this.$refs.form.clearValidate()
      this.show = false
    }
  }
}
</script>

<style scoped lang="scss"></style>
